package com.samoiloff.util.lang {
	import com.samoiloff.util.data.ArrItem;

	/**
	 * @author Damirr
	 */
	public class XLIFFIdsLangItem extends ArrItem {
		
		public function XLIFFIdsLangItem() {
			
		}
		
		public function update(obj : Object) : void {
			for (var propName:String in obj) {
				if (propName.search(/[^\d,]+/g) < 0) {
					var newIdLangItem:XLIFFIdLangItem = new XLIFFIdLangItem(propName, obj[propName]);
					var oldIdLangItem:XLIFFIdLangItem = getById(newIdLangItem.ids[0]);
					if (oldIdLangItem) {
						removeItem(oldIdLangItem);
					}
					_arr.push(newIdLangItem);
				}
			}
		}
		
		public function getItemAt(i:int):XLIFFIdLangItem {
			return XLIFFIdLangItem(_arr[i]);
		}
		
		public function containsId(id:*):Boolean {
			for (var i:int = 0; i<length; i++) {
				var building:XLIFFIdLangItem = getItemAt(i);
				var name:Object = building.containsId(String(id)) ? building.value : null;
				if (name) {
					return true;
				}
			}
			return false;
		}
		public function getItemById(id:*):* {
			for (var i:int = 0; i<length; i++) {
				var building:XLIFFIdLangItem = getItemAt(i);
				var name:Object = building.containsId(String(id)) ? building.value : null;
				if (name) {
					return name;
				}
			}
			return "Name not found";
		}
		
		public function getById(id:*):XLIFFIdLangItem {
			 for (var i:int = 0; i<length; i++) {
				var idLangItem:XLIFFIdLangItem = getItemAt(i);
				if (idLangItem.containsId(String(id))) {
					return idLangItem;
				}
			}
			return null;
		}
		
	}
}
